package mortal.game.control
{
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import flash.events.*;
    import modules.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.cache.CDItem.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.proxy.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.rules.*;
    import mortal.game.scene.player.entity.*;
    import mortal.game.view.avatar.*;
    import mortal.game.view.pack.*;
    import mortal.game.view.pack.define.*;
    import mortal.game.view.shop.*;
    import mortal.game.view.shortcuts.item.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class PackController extends Controller
    {
        public const posType:int = 0;
        public const extendPosType:int = 5;
        private const pageSize:int = 42;
        private var _packModule:PackModule;
        private var _packProxy:PackProxy;
        private var _packCache:PackPosTypeCache;
        private var _packExtendProxy:PackExtendProxy;
        private var _page:int;
        public var chooseAllLabel:Boolean = true;
        public var isBloodItemUseing:Boolean = false;
        public var isManaItemUseing:Boolean = false;
        public var autoUse:Boolean = true;
        public var playerUse:Boolean = false;
        public var autoUseSendToServer:Boolean = true;
        private var lightMask:LightMask;
        private var _guideUid:String;

        public function PackController()
        {
            this._packExtendProxy = new PackExtendProxy();
            this.Init();
            
        }

        private function Init() : void
        {
            this._packCache = cache.pack.backPackCache;
            this._packProxy = GameProxy.packProxy;
            
        }

        override protected function initView() : IView
        {
            if (this._packModule == null)
            {
                this._packModule = new PackModule();
                this._packModule.addEventListener(WindowEvent.SHOW, this.onPackShow);
                this._packModule.addEventListener(WindowEvent.CLOSE, this.onPackClose);
                this._packModule.x = 400;
                this._packModule.y = 100;
            }
            return this._packModule;
        }

        override public function popup() : void
        {
            
        }

        private function packModuleClose(event:WindowEvent) : void
        {
            Cache.instance.itemEffectCache.removeEffectItem();
            this._packModule.updateAllItem();
            
        }

        override protected function initServer() : void
        {
            Dispatcher.addEventListener(EventName.Item_CoolDown, this.onPackItemCoolDownHandler);
            NetDispatcher.addCmdListener(ServerCommand.BackPackCapacityChange, this.updateCapacityChange);
            NetDispatcher.addCmdListener(ServerCommand.UpdateItemCdData, updateItemCdDataByFresh);
            NetDispatcher.addCmdListener(ServerCommand.BackpackDataChange, this.noticeShortCut);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.noticeShortCut);
            Dispatcher.addEventListener(EventName.Trade_StatusChange, this.onTradeStatusChange);
            Dispatcher.addEventListener(EventName.GuideItemStrengthenChange, this.onGuideItemStrengthenChange);
            Dispatcher.addEventListener(EventName.Mail_StatusChange, this.onMainStatusChange);
            Dispatcher.addEventListener(EventName.Stall_StatusChange, this.onStallStatusChange);
            Dispatcher.addEventListener(EventName.BackPack_Destroy, this.destroy);
            Dispatcher.addEventListener(EventName.BackPack_DragInItem, this.dragInItem);
            Dispatcher.addEventListener(EventName.BackPack_DragInBack, this.dragInBack);
            Dispatcher.addEventListener(EventName.BackPack_Split, this.split);
            Dispatcher.addEventListener(EventName.BackPack_Tity, this.tidy);
            Dispatcher.addEventListener(EventName.BackPack_Use, this.onUseItemHandler);
            Dispatcher.addEventListener(EventName.BackPack_BulkUse, this.onBulkUseItemHandler);
            Dispatcher.addEventListener(EventName.BackPack_Equip, this.onUserEquipHandler);
            Dispatcher.addEventListener(EventName.BackPack_EquipMount, this.onUserEquipMountHandler);
            Dispatcher.addEventListener(EventName.Fast_USE_BackPackExtend, this.onFastUserExtendItemHandler);
            Dispatcher.addEventListener(EventName.Fast_Move_BackPackItem_ToWareHouse, this.fastMoveItemToWareHuse);
            Dispatcher.addEventListener(EventName.OpenBackPackExtendItem, this.openBackPackExtendItem);
            Dispatcher.addEventListener(EventName.BackPack_DragInExtendItem, this.dragInExtendItem);
            Dispatcher.addEventListener(EventName.FeedPet, this.useItemToFeedPet);
            Dispatcher.addEventListener(EventName.ItemUseReq, this.itemUseReq);
            Dispatcher.addEventListener(EventName.BackPackCodeItemPlayEffect, this.backPackCodeItemEffect);
            Dispatcher.addEventListener(EventName.ShowBackPackModule, this.showBackPackModule);
            Dispatcher.addEventListener(EventName.ShowGuideBackPackModule, this.showGuideBackPackModule);
            Dispatcher.addEventListener(EventName.Guide_MountCall, this.showGuideBackPackModule);
            Dispatcher.addEventListener(EventName.Guide_UseDrug, this.onGuideUseDrugHandler);
            
        }

        private function onPackShow(event:Event) : void
        {
            this.updatePack();
            this.updateMoney();
            this.updateExtendItems();
            this.changeVIPState();
            this._packModule.addEventListener(MouseEvent.MOUSE_OVER, this.mouse_over);
            this._packModule.addEventListener(MouseEvent.MOUSE_OUT, this.mouse_out);
            this._packModule.addEventListener(WindowEvent.CLOSE, this.packModuleClose);
            NetDispatcher.addCmdListener(ServerCommand.BackpackDataChange, this.updatePack);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.updatePack);
            NetDispatcher.addCmdListener(ServerCommand.MoneyUpdate, this.updateMoney);
            NetDispatcher.addCmdListener(ServerCommand.BackPackExtendItemsChange, this.updateExtendItems);
            NetDispatcher.addCmdListener(ServerCommand.BackPackExtendDataChange, this.updateExtendItems);
            NetDispatcher.addCmdListener(ServerCommand.VIPInfoUpdateCommand, this.changeVIPState);
            
        }

        private function onPackClose(event:Event) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.BackpackDataChange, this.updatePack);
            NetDispatcher.removeCmdListener(ServerCommand.BackPackItemsChange, this.updatePack);
            NetDispatcher.removeCmdListener(ServerCommand.MoneyUpdate, this.updateMoney);
            NetDispatcher.removeCmdListener(ServerCommand.BackPackExtendItemsChange, this.updateExtendItems);
            NetDispatcher.removeCmdListener(ServerCommand.BackPackExtendDataChange, this.updateExtendItems);
            Dispatcher.dispatchEvent(new DataEvent(EventName.PackWindowClose));
            this._guideUid = "";
            if (cache.shop.operType == ShopOperType.SALE)
            {
                cache.shop.operType = "";
            }
            
        }

        private function showBackPackModule(event:DataEvent) : void
        {
            var _loc_4:int = 0;
            var _loc_2:* = event.data as ItemData;
            view.show();
            var _loc_3:int = 2;
            if (_loc_2.category == ECategory._ECategoryEquip)
            {
                _loc_3 = 2;
            }
            if (_loc_2.category == ECategory._ECategoryProp)
            {
                _loc_3 = 1;
            }
            if (_loc_3 == 2)
            {
                _loc_4 = Cache.instance.pack.backPackCache.getIndexInEquip(_loc_2.uid);
            }
            if (_loc_3 == 1)
            {
                _loc_4 = Cache.instance.pack.backPackCache.getIndexInProp(_loc_2.uid);
            }
            var _loc_5:* = Math.floor((_loc_4 - 1) / this.pageSize);
            var _loc_6:* = _loc_4 % this.pageSize;
            this._packModule.setTabBarSelect(_loc_3);
            this._packModule.setPageTabBarSelect(_loc_5);
            this._packModule.updateAllItem();
            this._packModule.setPackItemPanelSelect((_loc_6 - 1));
            
        }

        private function showGuideBackPackModule(event:DataEvent) : void
        {
            var _loc_2:* = event.data as ItemData;
            this.guideItemUse(_loc_2, event.type);
            
        }

        private function onGuideUseDrugHandler(event:DataEvent) : void
        {
            var _loc_2:Array = null;
            if (!cache.guide.guideUseHong)
            {
                _loc_2 = cache.pack.backPackCache.getItemsByJudge(ItemsUtil.isChangeshengdan);
            }
            else if (!cache.guide.guideUseLan)
            {
                _loc_2 = cache.pack.backPackCache.getItemsByJudge(ItemsUtil.isButianwan);
            }
            if (_loc_2 && _loc_2.length > 0)
            {
                this.guideItemUse(_loc_2[0], EventName.Guide_UseDrug);
            }
            else if (_view && !_view.isHide)
            {
                view.hide();
            }
            
        }

        private function guideItemUse(param1:ItemData, param2:String) : void
        {
            var _loc_4:int = 0;
            view.show();
            var _loc_3:int = 2;
            if (param1.category == ECategory._ECategoryEquip)
            {
                _loc_3 = 2;
            }
            else if (param1.category == ECategory._ECategoryProp)
            {
                _loc_3 = 1;
            }
            else if (param1.category == ECategory._ECategoryDrug)
            {
                _loc_3 = 0;
            }
            if (_loc_3 == 2)
            {
                _loc_4 = Cache.instance.pack.backPackCache.getIndexInEquip(param1.uid);
            }
            else if (_loc_3 == 1)
            {
                _loc_4 = Cache.instance.pack.backPackCache.getIndexInProp(param1.uid);
            }
            else if (_loc_3 == 0)
            {
                _loc_4 = Cache.instance.pack.backPackCache.getIndexByUid(param1.uid);
            }
            var _loc_5:* = Math.floor((_loc_4 - 1) / this.pageSize);
            var _loc_6:* = (_loc_4 - 1) % this.pageSize;
            this._packModule.setTabBarSelect(_loc_3);
            this._packModule.setPageTabBarSelect(_loc_5);
            this._packModule.setPackItemPanelSelect(_loc_6);
            if (param2 == EventName.Guide_MountCall)
            {
                this._packModule.setGuidePackIndex(_loc_6, "双击装备坐骑，" + HTMLUtil.addColor("按H快速上下坐骑", "#ffec18"));
            }
            else if (param2 == EventName.ShowGuideBackPackModule && cache.role.entityInfo.level <= 25)
            {
                this._packModule.setGuidePackIndex(_loc_6);
            }
            else if (param2 == EventName.Guide_UseDrug)
            {
                this._packModule.setGuidePackIndex(_loc_6, "双击使用药品");
            }
            Cache.instance.itemEffectCache.addEffectItem(param1.itemInfo.item.code, ItemEffectType.LightMask);
            this._packModule.updateAllItem();
            this._guideUid = param1.uid;
            
        }

        private function mouse_over(event:MouseEvent) : void
        {
            if (cache.shop.isOpening || cache.vip.isVIP)
            {
                switch(Cache.instance.shop.operType)
                {
                    case ShopOperType.SALE:
                    {
                        CursorManager.showCursor(CursorManager.SELL);
                        break;
                    }
                    case ShopOperType.FIX:
                    {
                        CursorManager.showCursor(CursorManager.FIX);
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            
        }

        private function mouse_out(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.NO_CURSOR);
            
        }

        private function updateExtendItems(param1:Object = null) : void
        {
            if (!_view)
            {
                
            }
            (view as PackModule).updateExtendAllItems();
            if (param1)
            {
                if (param1["selectIndex"] != -1)
                {
                    this._packModule.updataPackExtendItemPanelSelectItem((param1["selectIndex"] - 1));
                }
                else
                {
                    this._packModule.updataPackExtendItemPanelSelectItem(-1);
                }
            }
            
        }

        private function updatePack(param1:Object = null) : void
        {
            (view as PackModule).updateAllItem();
            if (param1)
            {
                if (param1["selectIndex"] != -1)
                {
                    this._packModule.updataPackItemPanelSelectItem((param1["selectIndex"] - 1));
                }
                else
                {
                    this._packModule.updataPackItemPanelSelectItem(-1);
                }
            }
            
        }

        private function noticeShortCut(param1:Object = null) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ShortCutsItemChange));
            
        }

        private function changeVIPState(param1:Object = null) : void
        {
            (view as PackModule).showOrHideVIPBtn(cache.vip.isVIP);
            
        }

        private function updateMoney(param1:Object = null) : void
        {
            (view as PackModule).updateMoney();
            
        }

        private function dragInItem(event:DataEvent) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:String = null;
            var _loc_5:ItemData = null;
            var _loc_6:ItemData = null;
            var _loc_7:ItemData = null;
            var _loc_8:int = 0;
            var _loc_9:Boolean = false;
            this._page = this._packModule.pageTabBarSelect;
            var _loc_10:* = event.data as DragDropData;
            switch(_loc_10.fromPosType)
            {
                case EPlayerItemPosType._EPlayerItemPosTypeBag:
                {
                    _loc_2 = Cache.instance.pack.backPackCache.getIndexByUid(_loc_10.uid);
                    _loc_3 = this.pageSize * this._page + _loc_10.toIndex;
                    _loc_10.fromIndex = _loc_2;
                    _loc_10.toIndex = _loc_3;
                    if (_loc_3 <= Cache.instance.pack.backPackCache.sbag.capacity)
                    {
                        this._packProxy.moveInBag(_loc_10);
                    }
                    break;
                }
                case EPlayerItemPosType._EPlayerItemPosTypeWarehouse:
                {
                    _loc_2 = Cache.instance.pack.wareHousePackCache.getIndexByUid(_loc_10.uid);
                    _loc_3 = this.pageSize * this._page + _loc_10.toIndex;
                    _loc_10.fromIndex = _loc_2;
                    _loc_10.toIndex = _loc_3;
                    if (_loc_3 <= Cache.instance.pack.backPackCache.sbag.capacity)
                    {
                        this._packProxy.move(_loc_10);
                    }
                    break;
                }
                case EPlayerItemPosType._EPlayerItemPosTypeRole:
                {
                    GameController.player.unDress(_loc_10.uid);
                    break;
                }
                case EPlayerItemPosType._EPlayerItemPosTypeBagExtendBar:
                {
                    _loc_2 = Cache.instance.pack.backPackExtendPackCache.getIndexByUid(_loc_10.uid);
                    _loc_3 = this.pageSize * this._page + _loc_10.toIndex;
                    _loc_10.fromIndex = _loc_2;
                    _loc_10.toIndex = _loc_3;
                    this.moveExtendItem(_loc_10, this._packProxy);
                    break;
                }
                case EPlayerItemPosType._EPlayerItemPosTypeWarehouseExtendBar:
                {
                    _loc_2 = Cache.instance.pack.wareHouseExtendPackCache.getIndexByUid(_loc_10.uid);
                    _loc_3 = this.pageSize * this._page + _loc_10.toIndex;
                    _loc_10.fromIndex = _loc_2;
                    _loc_10.toIndex = _loc_3;
                    this.moveExtendItem(_loc_10, this._packProxy);
                    break;
                }
                case EPlayerItemPosType._EPlayerItemPosTypeGuildWarehouse:
                {
                    _loc_5 = _loc_10.fromItemData;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarehouseTake, _loc_5.data));
                    break;
                }
                default:
                {
                    break;
                }
            }
            
        }

        private function dragInBack(event:DataEvent) : void
        {
            var _loc_2:* = event.data as DragDropData;
            switch(_loc_2.fromPosType)
            {
                case 0:
                {
                    break;
                }
                case EPlayerItemPosType._EPlayerItemPosTypeRole:
                {
                    GameController.player.unDress(_loc_2.uid);
                    break;
                }
                default:
                {
                    break;
                }
            }
            
        }

        private function split(event:DataEvent) : void
        {
            if (event.data)
            {
                this._packProxy.split(event.data["uid"] as String, event.data["amount"] as int);
            }
            
        }

        private function tidy(event:DataEvent) : void
        {
            this._packProxy.tidy();
            
        }

        private function onBulkUseItemHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data["itemData"];
            var _loc_3:* = event.data["amount"];
            if (ItemsUtil.isPetDrug(_loc_2))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetFeedInPack, {itemData:_loc_2, amount:_loc_3}));
            }
            else
            {
                GameProxy.packProxy.useItem(_loc_2.uid, _loc_3);
            }
            
        }

        private function onUseItemHandler(event:DataEvent) : void
        {
            this.useItem(event.data as ItemData);
            
        }

        public function useItem(param1:ItemData) : void
        {
            var _loc_4:CDBackPackItem = null;
            var _loc_5:BuffInfo = null;
            var _loc_2:* = param1.uid;
            var _loc_3:* = param1.itemInfo.item.name;
            if (!ItemsUtil.isPetUse(param1) && param1.itemInfo.item.level > cache.role.entityInfo.level)
            {
                MsgManager.addBroadCast("您需要" + param1.itemInfo.item.level + "级才能使用该物品");
            }
            else if (ItemsUtil.isPackage(param1))
            {
                this.fastUseExtendItem(param1);
            }
            else if (ItemsUtil.isSkillBook(param1))
            {
                GameProxy.skillProxy.learnByBook(param1);
            }
            else if (ItemsUtil.isPetSkillBook(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetOpenSkillStudyTab, param1));
            }
            else if (ItemsUtil.isPropOfflineAddExperience(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.OfflineExpPropUse));
            }
            else if (ItemsUtil.isPropColorStone(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.UsePropColorStone, param1));
            }
            else if (ItemsUtil.isPropTransportFlushToken(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.UseTransportFlushToken, param1));
            }
            else if (ItemsUtil.isTaskSilverNote(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.UseTaskSilverNote, param1));
            }
            else if (ItemsUtil.isTrumpet(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ChatShowSpeaker));
            }
            else if (ItemsUtil.isHuntMap(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ItemUse_HuntMap, param1));
            }
            else if (ItemsUtil.isHuntShovel(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ItemUse_HuntShovel, param1));
            }
            else if (ItemsUtil.isEquipStrengthenLuckRune(param1) || ItemsUtil.isEquipStrengthenMaterial(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Equipment_DoCast_Strengthen, param1));
            }
            else if (ItemsUtil.isEquipRefineLuckRune(param1) || ItemsUtil.isEquipRefineMaterial(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Equipment_DoCast_Refine, param1));
            }
            else if (ItemsUtil.isEquipMakeHoleRune(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Equipment_DoCast_MakeHole, param1));
            }
            else if (ItemsUtil.isEquipEmbedRune(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Equipment_DoCast_EmbedJewel, param1));
            }
            else if (ItemsUtil.isEquipRemoveRune(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Equipment_DoCast_RemoveJewel, param1));
            }
            else if (ItemsUtil.isJewelComposeRune(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Equipment_DoCast_ComposeJewel, param1));
            }
            else if (ItemsUtil.isEquipRecastMaterial(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Equipment_DoCast_Recast, param1));
            }
            else if (ItemsUtil.isPetDrug(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetFeedInPack, {itemData:param1, amount:1}));
            }
            else if (ItemsUtil.isChangeShape(param1))
            {
                this.confirmChangeShape(param1);
            }
            else if (ItemsUtil.isFlower(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.FlowerUseInPack, param1));
            }
            else if (ItemsUtil.isPetSkillRand(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetSkillOpenRefreshWindow, param1));
            }
            else if (ItemsUtil.isKillEvilToken(param1))
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.KillEvilTaskUsePropFromPack, param1));
            }
            else if (ItemsUtil.isFish(param1))
            {
                if (RolePlayer.instance.isTurned)
                {
                    MsgManager.addBroadCast("幻化状态，不可烤鱼");
                    
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.StartRoastFish, param1));
            }
            else if (ItemsUtil.isNotCanUse(param1))
            {
                MsgManager.addBroadCast("该道具在背包中无法直接使用！");
            }
            else if (ItemsUtil.isCanUseInBag(param1))
            {
                if (cache.guide.guideUseDrug)
                {
                    if (ItemsUtil.isChangeshengdan(param1))
                    {
                        cache.guide.guideUseHong = true;
                        this.onGuideUseDrugHandler(null);
                    }
                    else if (ItemsUtil.isButianwan(param1))
                    {
                        cache.guide.guideUseLan = true;
                        this.onGuideUseDrugHandler(null);
                    }
                }
                _loc_4 = cache.timeCdCache.getCdTime(param1);
                if (_loc_4)
                {
                    if (_loc_4.isRequestCd || _loc_4.isCoolDown)
                    {
                        
                    }
                }
                else
                {
                    _loc_4 = cache.timeCdCache.addCDTime(param1);
                }
                if (_loc_2 == null)
                {
                    _loc_2 = cache.pack.backPackCache.getFirstItemUid(_loc_3);
                }
                if (_loc_2)
                {
                    _loc_4.startItemCd();
                    if (ItemsUtil.isAttrDrug(param1))
                    {
                        _loc_5 = cache.buff.getCanNotUseBuffInfo(param1);
                        if (_loc_5)
                        {
                            this.showItemTips(_loc_5, param1);
                            
                        }
                    }
                    GameProxy.packProxy.useItem(_loc_2);
                }
            }
            else if (ItemsUtil.isOpenFunc(param1))
            {
                if (ItemsUtil.isTaskLoopBook(param1))
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.UseTaskFlushLoopBook, param1));
                }
            }
            
        }

        private function confirmChangeShape(param1:ItemData) : void
        {
            var closeHandler:Function;
            var itemData:* = param1;
            closeHandler = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    GameProxy.packProxy.useItem(itemData.uid);
                }
                
            }
            ;
            if (GameController.stall.isInStall)
            {
                MsgManager.addBroadCast("摆摊状态下不能幻化");
                
            }
            var color1:* = ColorConfig.instance.getItemColor(itemData.color).color;
            if (RolePlayer.instance.isTurned)
            {
                Alert.show("使用" + HTMLUtil.addColor("[" + itemData.itemInfo.item.name + "]", color1) + ",是否确定退出当前幻化状态", null, Alert.OK | Alert.CANCEL, null, closeHandler);
            }
            else
            {
                GameProxy.packProxy.useItem(itemData.uid);
            }
            
        }

        private function showItemTips(param1:BuffInfo, param2:ItemData) : void
        {
            var closeHandler:Function;
            var buffInfo:* = param1;
            var itemData:* = param2;
            closeHandler = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    GameProxy.packProxy.useItem(itemData.uid);
                }
                
            }
            ;
            var color1:* = ColorConfig.instance.getItemColor(itemData.color).color;
            var color2:* = GlobalStyle.color5;
            Alert.show("角色同一时间只能保持1种属性增益效果,\n你确定要用" + HTMLUtil.addColor("[" + itemData.itemInfo.item.name + "]", color1) + "覆盖" + HTMLUtil.addColor("[" + buffInfo.tstate.name + "]", color2) + "吗？", null, Alert.OK | Alert.CANCEL, null, closeHandler);
            
        }

        private function useItemToFeedPet(event:DataEvent) : void
        {
            var _loc_3:int = 0;
            var _loc_4:String = null;
            var _loc_5:CDBackPackItem = null;
            var _loc_2:* = event.data["itemData"] as ItemData;
            if (_loc_2)
            {
                _loc_3 = event.data["amount"] as int;
                _loc_4 = event.data["petUid"] as String;
                if (_loc_2.isCanCD())
                {
                    _loc_5 = cache.timeCdCache.getCdTime(_loc_2);
                    if (_loc_5)
                    {
                        if (_loc_5.isRequestCd || _loc_5.isCoolDown)
                        {
                            
                        }
                    }
                    else
                    {
                        _loc_5 = cache.timeCdCache.addCDTime(_loc_2);
                    }
                    if (_loc_5)
                    {
                        _loc_5.startItemCd();
                        GameProxy.packProxy.useItem(_loc_2.uid, _loc_3, [_loc_4]);
                    }
                }
                else
                {
                    GameProxy.packProxy.useItem(_loc_2.uid, _loc_3, [_loc_4]);
                }
            }
            
        }

        public function useEquipItem(param1:ItemData) : void
        {
            if (param1)
            {
                if (param1.itemInfo.item.level > cache.role.entityInfo.level)
                {
                    MsgManager.addBroadCast("您需要" + param1.itemInfo.item.level + "级才能装备该物品");
                }
                else
                {
                    GameController.player.dress(param1.posType, param1.uid);
                }
            }
            
        }

        public function equipMount(param1:ItemData) : void
        {
            if (param1)
            {
                if (param1.itemInfo.item.level > cache.role.entityInfo.level)
                {
                    MsgManager.addBroadCast("您需要" + param1.itemInfo.item.level + "级才能装备该坐骑");
                }
                else
                {
                    GameController.player.dress(param1.posType, param1.uid);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.CallMounts, param1));
                }
            }
            
        }

        private function onUserEquipHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as ItemData;
            if (this._guideUid && this._guideUid == _loc_2.uid)
            {
                this._guideUid = "";
                this._packModule.cacelPackIndexGuide();
            }
            this.useEquipItem(_loc_2);
            
        }

        private function onUserEquipMountHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as ItemData;
            if (this._guideUid && this._guideUid == _loc_2.uid)
            {
                this._guideUid = "";
                this._packModule.cacelPackIndexGuide();
            }
            this.equipMount(_loc_2);
            
        }

        private function itemUseReq(event:DataEvent) : void
        {
            var _loc_2:* = event.data as ItemData;
            var _loc_3:* = _loc_2.uid;
            var _loc_4:* = Cache.instance.pack.backPackCache.getIndexByUid(_loc_2.uid);
            if (_loc_2)
            {
                if (_loc_2.itemInfo.item.category == ECategory._ECategoryEquip)
                {
                    this.useEquipItem(_loc_2);
                }
                else if (_loc_2.itemInfo.item.category == ECategory._ECategoryJewel)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Show, _loc_2));
                }
                else
                {
                    this.useItem(_loc_2);
                }
            }
            
        }

        private function destroy(event:DataEvent) : void
        {
            var _loc_2:* = event.data as PackItem;
            this._packProxy.remove(_loc_2.itemData.uid, _loc_2.posType);
            
        }

        private function onTradeStatusChange(event:DataEvent) : void
        {
            this.updatePack();
            
        }

        private function onGuideItemStrengthenChange(event:DataEvent) : void
        {
            this.updatePack();
            
        }

        private function onMainStatusChange(event:DataEvent) : void
        {
            this.updatePack();
            
        }

        private function onStallStatusChange(event:DataEvent) : void
        {
            this.updatePack();
            
        }

        public function get packModule() : PackModule
        {
            return this._packModule;
        }

        private function dragInExtendItem(event:DataEvent) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_2:* = event.data as DragDropData;
            switch(_loc_2.fromPosType)
            {
                case EPlayerItemPosType._EPlayerItemPosTypeBag:
                {
                    _loc_3 = _loc_2.fromIndex + this.pageSize * this._packModule.pageTabBarSelect;
                    _loc_2.fromIndex = _loc_3;
                    this.moveExtendItem(_loc_2, this._packCache);
                    break;
                }
                case EPlayerItemPosType._EPlayerItemPosTypeWarehouse:
                {
                    _loc_3 = _loc_2.fromIndex + this.pageSize * GameController.wareHouse.wareHouseModule.pageTabBarSelect;
                    _loc_2.fromIndex = _loc_3;
                    this.moveExtendItem(_loc_2, this._packCache);
                    break;
                }
                case EPlayerItemPosType._EPlayerItemPosTypeWarehouseExtendBar:
                {
                    break;
                }
                case EPlayerItemPosType._EPlayerItemPosTypeBagExtendBar:
                {
                    _loc_3 = _loc_2.fromIndex;
                    _loc_2.fromIndex = _loc_3;
                    if (_loc_4 <= Cache.instance.pack.backPackExtendPackCache.sbag.capacity)
                    {
                        this._packExtendProxy.moveInBag(_loc_2);
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            
        }

        private function updateCapacityChange(param1:Object) : void
        {
            var _loc_2:* = Cache.instance.pack.backPackCache.capacity;
            var _loc_3:* = param1 as SBagCapacityChangeMsg;
            var _loc_4:* = Math.abs(_loc_3.newCapacity - _loc_2);
            if (_loc_3.newCapacity > _loc_2)
            {
                Cache.instance.pack.backPackCache.addNullItemToEnd(_loc_4);
                this.updatePack();
            }
            Cache.instance.pack.backPackCache.capacity = _loc_3.newCapacity;
            this._packModule.updateCapacity(Cache.instance.pack.backPackCache);
            
        }

        private function moveExtendItem(param1:DragDropData, param2) : void
        {
            var len:int;
            var toItemIsExtend:Boolean;
            var _cache:*;
            var _proxy:*;
            var toItemCategory:int;
            var toItemProp:int;
            var toIndex:int;
            var isTidy:Boolean;
            var pathOfDrag:String;
            var fromItemEffect:int;
            var toItemEffect:int;
            var dragDropData:* = param1;
            var proxy:* = param2;
            var showAlterWindow:* = function (param1:String, param2:Boolean, param3:String = null) : void
            {
                var posName:* = param1;
                var _isTidy:* = param2;
                var path:* = param3;
                if (_cache.getLengthOfNullItemFromAllItem() >= len)
                {
                    var closeHandler1:* = function (param1:int) : void
                {
                    if (param1 == Alert.YES)
                    {
                        if (toIndex <= _cache.sbag.capacity)
                        {
                            _proxy.move(dragDropData, _isTidy, path);
                        }
                    }
                    
                }
                ;
                    Alert.show("确定将会重新整理" + posName, null, Alert.YES | Alert.CANCEL, null, closeHandler1);
                }
                else
                {
                    MsgManager.addBroadCast(posName + "容量不足！");
                }
                
            }
            ;
            var toItemData:* = dragDropData.toItemData;
            var fromItemData:* = dragDropData.fromItemData;
            var fromIndex:* = dragDropData.fromIndex;
            toIndex = dragDropData.toIndex;
            var fromPosType:* = dragDropData.fromPosType;
            var toPosType:* = dragDropData.toPosType;
            var uid:* = dragDropData.uid;
            if (!ItemsUtil.isPackage(fromItemData))
            {
                
            }
            if (toItemData == null)
            {
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouse && toPosType == EPlayerItemPosType._EPlayerItemPosTypeBagExtendBar)
                {
                    GameProxy.packExtendProxy.move(dragDropData);
                    
                }
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeBag && toPosType == EPlayerItemPosType._EPlayerItemPosTypeBagExtendBar)
                {
                    GameProxy.packExtendProxy.move(dragDropData);
                    
                }
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeBagExtendBar && toPosType == EPlayerItemPosType._EPlayerItemPosTypeBag)
                {
                    _cache = Cache.instance.pack.backPackCache;
                    _proxy = GameProxy.packProxy;
                    toItemIsExtend;
                    len = (fromItemData.itemInfo.item.effect + 1);
                    this.showAlterWindow("背包", true);
                }
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouseExtendBar && toPosType == EPlayerItemPosType._EPlayerItemPosTypeBag)
                {
                    _cache = Cache.instance.pack.wareHousePackCache;
                    _proxy = GameProxy.wareHouseProxy;
                    toItemIsExtend;
                    len = (fromItemData.itemInfo.item.effect + 1);
                    this.showAlterWindow("仓库", true, BackPackWareHouseMoveType.WareHouseExtendToBackPack);
                }
            }
            else
            {
                toItemCategory = toItemData.itemInfo.item.category;
                toItemProp = toItemData.itemInfo.item.type;
                fromItemEffect = fromItemData.itemInfo.item.effect;
                toItemEffect = toItemData.itemInfo.item.effect;
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeBagExtendBar && toPosType == EPlayerItemPosType._EPlayerItemPosTypeBag)
                {
                    _cache = Cache.instance.pack.backPackCache;
                    _proxy = GameProxy.packProxy;
                    if (ItemsUtil.isPackage(toItemData))
                    {
                        pathOfDrag = BackPackWareHouseMoveType.BackPackExtendToBackPack;
                        toItemIsExtend;
                        len = fromItemEffect - toItemEffect;
                    }
                }
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeBag && toPosType == EPlayerItemPosType._EPlayerItemPosTypeBagExtendBar)
                {
                    _cache = Cache.instance.pack.backPackCache;
                    _proxy = GameProxy.packProxy;
                    if (ItemsUtil.isPackage(toItemData))
                    {
                        pathOfDrag = BackPackWareHouseMoveType.BackPackToBackPackExtend;
                        toItemIsExtend;
                        len = fromItemEffect - toItemEffect;
                    }
                }
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouse && toPosType == EPlayerItemPosType._EPlayerItemPosTypeBagExtendBar)
                {
                    _cache = Cache.instance.pack.wareHousePackCache;
                    _proxy = GameProxy.wareHouseProxy;
                    if (ItemsUtil.isPackage(toItemData))
                    {
                        pathOfDrag = BackPackWareHouseMoveType.WareHouseToBackPackExtend;
                        toItemIsExtend;
                        len = fromItemEffect - toItemEffect;
                    }
                }
                if (fromPosType == EPlayerItemPosType._EPlayerItemPosTypeWarehouseExtendBar && toPosType == EPlayerItemPosType._EPlayerItemPosTypeBag)
                {
                    _cache = Cache.instance.pack.backPackCache;
                    _proxy = GameProxy.packProxy;
                    if (ItemsUtil.isPackage(toItemData))
                    {
                        pathOfDrag = BackPackWareHouseMoveType.WareHouseExtendToBackPack;
                        toItemIsExtend;
                        len = fromItemEffect - toItemEffect;
                    }
                }
            }
            if (!pathOfDrag)
            {
                
            }
            switch(pathOfDrag)
            {
                case BackPackWareHouseMoveType.BackPackToBackPackExtend:
                {
                    if (toIndex <= _cache.sbag.capacity)
                    {
                        if (len >= 0)
                        {
                            isTidy;
                            _proxy.move(dragDropData);
                        }
                        else
                        {
                            isTidy;
                            this.showAlterWindow("背包", isTidy);
                        }
                    }
                    break;
                }
                case BackPackWareHouseMoveType.BackPackExtendToBackPack:
                {
                    if (toIndex <= _cache.sbag.capacity)
                    {
                        if (len > 0)
                        {
                            isTidy;
                            this.showAlterWindow("背包", isTidy);
                        }
                        else
                        {
                            isTidy;
                            _proxy.move(dragDropData);
                        }
                    }
                    break;
                }
                case BackPackWareHouseMoveType.WareHouseToBackPackExtend:
                {
                    if (toIndex <= _cache.sbag.capacity)
                    {
                        if (len > 0)
                        {
                            isTidy;
                            _proxy.move(dragDropData);
                        }
                        else
                        {
                            isTidy;
                            this.showAlterWindow("背包", isTidy, BackPackWareHouseMoveType.WareHouseToBackPackExtend);
                        }
                    }
                    break;
                }
                case BackPackWareHouseMoveType.WareHouseExtendToBackPack:
                {
                    if (toIndex <= _cache.sbag.capacity)
                    {
                        if (len > 0)
                        {
                            isTidy;
                            this.showAlterWindow("仓库", isTidy, BackPackWareHouseMoveType.WareHouseExtendToBackPack);
                        }
                        else
                        {
                            isTidy;
                            _proxy.move(dragDropData);
                        }
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            
        }

        private function onFastUserExtendItemHandler(event:DataEvent) : void
        {
            this.fastUseExtendItem(event.data as ItemData);
            
        }

        private function fastUseExtendItem(param1:ItemData) : void
        {
            var _loc_7:DragDropData = null;
            if (!param1)
            {
                
            }
            var _loc_2:* = param1.uid;
            var _loc_3:* = EPlayerItemPosType._EPlayerItemPosTypeBag;
            var _loc_4:* = EPlayerItemPosType._EPlayerItemPosTypeBagExtendBar;
            var _loc_5:* = Cache.instance.pack.backPackCache.getIndexByUid(_loc_2);
            var _loc_6:* = Cache.instance.pack.backPackExtendPackCache.getFirstNullItemIndex();
            if (Cache.instance.pack.backPackExtendPackCache.getFirstNullItemIndex() != -1)
            {
                _loc_7 = new DragDropData(_loc_3, _loc_4, _loc_2, _loc_5, (_loc_6 + 1), null, null);
                GameProxy.packExtendProxy.move(_loc_7);
            }
            else
            {
                MsgManager.addBroadCast("背包扩展槽已满！");
            }
            
        }

        private function fastMoveItemToWareHuse(event:DataEvent) : void
        {
            var _loc_9:DragDropData = null;
            var _loc_2:* = event.data as PackItem;
            if (!_loc_2.itemData)
            {
                
            }
            var _loc_3:* = _loc_2.itemData;
            var _loc_4:* = _loc_3.uid;
            var _loc_5:* = EPlayerItemPosType._EPlayerItemPosTypeBag;
            var _loc_6:* = EPlayerItemPosType._EPlayerItemPosTypeWarehouse;
            var _loc_7:* = Cache.instance.pack.backPackCache.getIndexByUid(_loc_4);
            var _loc_8:* = Cache.instance.pack.wareHousePackCache.getFirstNullItemIndex();
            if (Cache.instance.pack.wareHousePackCache.getFirstNullItemIndex() != -1)
            {
                _loc_9 = new DragDropData(_loc_5, _loc_6, _loc_4, _loc_7, (_loc_8 + 1), null, null);
                GameProxy.wareHouseProxy.move(_loc_9);
            }
            else
            {
                MsgManager.addBroadCast("仓库已满！");
            }
            
        }

        private function openBackPackExtendItem(event:DataEvent) : void
        {
            GameProxy.packExtendProxy.openExtendItem(PackCache.Type_BackPackExtend);
            
        }

        private function onPackItemCoolDownHandler(event:DataEvent) : void
        {
            var _loc_6:CDBackPackItem = null;
            var _loc_2:* = event.data as Object;
            var _loc_3:* = _loc_2["uid"];
            var _loc_4:* = Cache.instance.pack.backPackCache.getIndexByUid(_loc_3);
            var _loc_5:* = Cache.instance.pack.backPackCache.getItemDataByIndex(_loc_4) as ItemData;
            if (Cache.instance.pack.backPackCache.getItemDataByIndex(_loc_4) as ItemData)
            {
                _loc_6 = cache.timeCdCache.getCdTime(_loc_5);
                if (_loc_6 && _loc_6.isCoolDown == false)
                {
                    _loc_6.startCoolDown();
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ItemUse, _loc_6));
                }
            }
            
        }

        private function backPackCodeItemEffect(event:DataEvent) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            if (this.initView())
            {
                _loc_2 = Cache.instance.pack.backPackCache.getIndexByCode(event.data as int);
                Cache.instance.itemEffectCache.addEffectItem(event.data as int, ItemEffectType.LightMask);
                _loc_3 = Math.floor((_loc_2 - 1) / this.pageSize);
                _loc_4 = (_loc_2 - 1) % this.pageSize;
                this._packModule.setTabBarSelect(0);
                this._packModule.setPageTabBarSelect(_loc_3);
                this._packModule.updateAllItem();
            }
            
        }

        public static function updateItemCdDataByFresh(param1) : void
        {
            ItemCoolDownUtil.instance.updateItemCdByFresh(param1 as SDrugCanUseDtMsg);
            
        }

    }
}
